@extends('layouts.app')
@section('title', isset($topic->id)?'话题创建':'话题编辑')
@section('content')

<div class="layui-col-md-offset3 layui-col-md6" style="margin-top: 50px;">
  <div class="layui-card" style="border: 1px solid #eee;">
    <div class="layui-card-header" style="background-color: #eee">
      <h4>
        话题 /
          @if($topic->id)
            编辑 #{{ $topic->id }}
          @else
            创建
          @endif
      </h4>
    </div>
    <div class="layui-card-body">
      @if(isset($topic->id))
        <form method="POST" action="{{route('topics.update', $topic->id)}}" class="layui-form">
        {{ method_field('PATCH') }}
      @else
        <form method="POST" action="{{route('topics.store')}}" class="layui-form">
      @endif
        {{ csrf_field() }}
        <div class="layui-form-item">
          <label class="layui-form-label">标题：</label>
          <div class="layui-input-block">
            <input type="text" name="title" lay-verify="required" autocomplete="off" placeholder="请填入标题" class="layui-input" value="{{ old('title', $topic->title ) }}">
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">分类：</label>
          <div class="layui-input-block">
            <select name="category_id" {{ $topic->id ? '' : 'selected' }} lay-verify="required">
              <option value="" >请选择分类</option>
              @foreach ($categories as $value)
                <option value="{{ $value->id }}" {{ $topic->category_id == $value->id ? 'selected' : '' }}>{{ $value->name }}</option>
              @endforeach
            </select>
          </div>
        </div>
        <div class="layui-form-item layui-form-text">
          <label class="layui-form-label">内容：</label>
          <div class="layui-input-block">
            <textarea placeholder="请至少输入3个字符的内容" rows="6" name="body" lay-verify="required" class="layui-textarea">{{ old('body', $topic->body) }}</textarea>
          </div>
        </div>
        <div class="layui-form-item">
          <button class="layui-btn ok-button" lay-submit lay-filter="formEdit">保存</button>
        </div>
      </form>
    </div>
  </div>
</div>

@endsection

@section('js')
<script>
  layui.use('form', function(){
    var form = layui.form;
  });
</script>
@endsection
